package top.hkyzf.study.leetcode.tree;

import java.util.HashSet;
import java.util.Set;

/**
 * description: 
 * @author zhufeng
 * @date 2024/3/12 0012 9:27
 * @version V1.0
 */
public class FindElements {
    Set<Integer> set = new HashSet<>();
    public FindElements(TreeNode root) {
        dfs(root, 0);
    }

    private void dfs(TreeNode node, int val) {
        if (node == null) {
            return;
        }
        node.val = val;
        set.add(val);
        dfs(node.left, 2*val+1);
        dfs(node.right, 2*val+2);
    }

    public boolean find(int target) {
        return set.contains(target);
    }

}
